package com.heima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.mapper.TypeMapper;
import com.heima.pojo.Type;
import com.heima.pojo.dto.PagingQueryDTO;
import com.heima.pojo.vo.PagingVO;
import com.heima.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TypeServicelmpl implements TypeService {
    @Autowired
    private TypeMapper typeMapper;
    /**查询设备类型
     * @param receiveDto
     * @return
     */
    @Override
    public PagingVO slectType(PagingQueryDTO receiveDto) {
        PageHelper.startPage(receiveDto.getPageIndex(),receiveDto.getPageSize());
        Page<Type> type = typeMapper.slectType(receiveDto.getName());
        PagingVO pagingVO = new PagingVO();
        pagingVO.setCurrentPageRecords(type);
        pagingVO.setPageIndex(receiveDto.getPageIndex());
        pagingVO.setPageSize(receiveDto.getPageSize());
        pagingVO.setTotalCount((int) type.getTotal());
        pagingVO.setTotalPage(type.getPages());
        return pagingVO;
    }

    /**新增设备
     * @param type
     * @return
     */
    @Override
    public Boolean addType(Type type) {
        return typeMapper.addType(type);
    }

    /**
     * @param typeId
     * @param type
     * @return
     */
    @Override
    public Boolean updateType(Long typeId, Type type) {
         return typeMapper.updateType(typeId,type);
    }

    /**删除设备
     * @param typeId
     * @return
     */
    @Override
    public Boolean deleteType(Long typeId) {
        return typeMapper.deleteType(typeId);
    }
}
